package com.whenjun.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.ifootbook.util.EmptyUtil;
import com.whenjun.dto.door.IscDoorDTO;
import com.whenjun.dto.door.IscDoorReq;
import com.whenjun.dto.person.IscPersonDTO;
import com.whenjun.entity.IscDoor;
import com.whenjun.entity.IscPerson;
import com.whenjun.mapper.IscDoorMapper;
import com.whenjun.service.IIscDoorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.whenjun.util.IPageUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * isc 门禁点 服务实现类
 * </p>
 *
 * @author whenjun
 * @since 2024-02-20
 */
@Service
public class IscDoorServiceImpl extends MPJBaseServiceImpl<IscDoorMapper, IscDoor> implements IIscDoorService {

    @Transactional
    public IPage<IscDoorDTO> KqDoors(IscDoorReq iscDoorReq) {
        Page<IscDoor> page = new Page<>(iscDoorReq.getPage(), iscDoorReq.getSize());

        IPage<IscDoor> iscDoorList = this.lambdaQuery()
                .like(!EmptyUtil.isEmpty(iscDoorReq.getName()), IscDoor::getName, iscDoorReq.getName())
                .or()
                .like(!EmptyUtil.isEmpty(iscDoorReq.getName()), IscDoor::getDescription, iscDoorReq.getName())
                .orderByAsc(IscDoor::getName)
                .page(page)
                ;

        IPage<IscDoorDTO> iscDoorDTOIPage = IPageUtil.trans(iscDoorList);

        return iscDoorDTOIPage;
    }
}
